import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dio_lib/dio_lib_export.dart';

void main() {
  HttpConfig dioConfig = HttpConfig(baseUrl: "https://gank.io/");
  HttpClient client = HttpClient(dioConfig: dioConfig);
  Get.put<HttpClient>(client);
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage());
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
    get();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('MyHomePage'),
        ),
        body: Center(child: Container(child: Text('Hello GetX'))));
  }

  void get() async {
    HttpResponse appResponse =
        await Get.find<HttpClient>().get("api/v2/banners");
    if (appResponse.ok) {
      debugPrint("====" + appResponse.data.toString());
    } else {
      debugPrint("====" + appResponse.error.toString());
    }

    Get.defaultDialog(title: 'Test Dialog');
  }
}
